package modelLayer;

import java.util.ArrayList;

public class EmployeeContainer {
   private ArrayList<Employee> employees;
   private static EmployeeContainer instance;
   
   private EmployeeContainer() {
       employees = new ArrayList<>();
   }
    
   public static EmployeeContainer getInstance() {
       if(instance == null) {
           instance = new EmployeeContainer();
        }
        
       return instance;
   }
    
   public void addEmployee(Employee emp) {
        employees.add(emp);
   }
   
   public Employee findEmployee(int cprNo) {
       boolean found = false;
       int index = 0;
       while(index < employees.size() && !found) {
           Employee emp = employees.get(index);
           if(emp.getCpr() == cprNo) {
               found = true;
            }
            else {
                return null;
            }
        }
        
        if(found) {
            return employees.get(index);
        }
        else {
            return null;
        }
   }
    
   public void removeEmployee(Employee emp) {
       employees.remove(emp);
   }
    
   public int numberOfEmployees() {
       return employees.size();
   }
}
